package org.d7_buffered_stream;

import java.awt.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 将顺序错乱的出师表复制到新文件中，并排序
 */
public class Test {
    public static void main(String[] args) {


        try(
                //2.创建缓冲字符输入流管道与源文件接通

              BufferedReader br = new BufferedReader(new FileReader("D:\\idea\\idea code\\java-practice\\practice\\change\\file-oi-app\\src\\test\\csb.test"));
              BufferedWriter bw = new  BufferedWriter(new FileWriter("D:\\idea\\idea code\\java-practice\\practice\\change\\file-oi-app\\src\\test\\newcsb.test"))
                ) {


            //1.创建一个集合 ArrayList集合存储每段内容
            List<String> data = new ArrayList<>();

            //3.按照行读取每段，存入到集合中
            String line;
            while ((line = br.readLine()) != null){
                data.add(line);
            }
             //4。对list集合中的每段文章进行排序
            Collections.sort(data);
            System.out.println(line);

            //5.遍历list集合的内容，一次写到新文件中去
            for (String ln : data) {
                bw.write(ln);
                bw.newLine();
            }

            } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
